import { Component, OnInit, OnDestroy, ChangeDetectorRef, Inject, forwardRef } from '@angular/core';
import { path } from '../../../../path.config';
import { AppComponent } from '../../../../app.component';

import { masterService } from '../../../../../lib/master.service';
import { saveVarService } from '../../../../../lib/saveVar.service';
import { NzModalService } from 'ng-zorro-antd';
@Component({
    selector: 'exchange-card-query-grid',
    templateUrl: './exchange-card-query-grid.component.html',
    styleUrls: ['./exchange-card-query-grid.component.css'],
    providers: [forwardRef(() => AppComponent)]
})
export class ExchangeCardQueryGridComponent implements OnInit {
    // api
    // 表格数据
    public getList: any = path.cardManagement.cardInfo.getList;
    // 列表项数组
    public rows: Array<any> = [];
    public filter = {
        code: ''
    }

    constructor(public _masterService: masterService,
        public cdRef: ChangeDetectorRef,
        public _saveVarService: saveVarService,
        private confirmServ: NzModalService,
        @Inject(forwardRef(() => AppComponent)) public app: AppComponent) { }

    ngOnInit() {
    }

    // 渲染表格
    public onChangeTable = (urlObj) => {
        this.filter.code = urlObj.code;
        this._masterService
            .getData(this.getList, this.filter)
            .subscribe((res) => {
                if (res.statusCode == 200) {
                    this.rows = res.data;
                    if (this.rows.length == 0) {
                        this.app.toastError('该卡号不存在！');
                    }
                    this.cdRef.detectChanges();
                } else {
                    this.app.toastError('错误信息： ' + res.errorMessage);
                }
            })
    }
}
